package com.roselism.mobilesafe.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.roselism.mobilesafe.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by simon on 2016/4/27.
 */
public class GridHomeAdapter extends BaseAdapter {

    Context mContext;
    int[] resIds = new int[]{
            R.mipmap.home_safe,
            R.mipmap.home_callmsgsafe,
            R.mipmap.home_apps,
            R.mipmap.home_taskmanager,
            R.mipmap.home_trojan,
            R.mipmap.home_sysoptimize,
            R.mipmap.home_tools,
            R.mipmap.home_netmanager,
            R.mipmap.home_settings};
    String[] names = new String[]{"手机防盗", "通讯卫士", "软件管理", "进程管理", "流量统计", "手机杀毒", "缓存清理", "高级工具", "设置工具"};

    public GridHomeAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public Object getItem(int position) {
        return names[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.grid_item_home, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else
            viewHolder = (ViewHolder) convertView.getTag();
        viewHolder.image.setImageResource(resIds[position]);
        viewHolder.name.setText(names[position]);

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.image) ImageView image;
        @Bind(R.id.name) TextView name;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
